﻿#region (C) Header Region @ 2012
//====================================================
// 文件: ProcessBar.cs
// 描述: 在页面显示等待的进度条
// 路径: Antu.Core\Utilities\ProcessBar.cs
// ******************版本1 ******************
// 人员: 蔡金保    时间 : 2012/11/15 11:26:28
// 注释:
//====================================================
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Antu.Utilities
{
    public class ProcessBar
    {
        public static void Process(Page page, string tag)
        {
            page.Response.Write("<div id=\"LayProcessBar\" name=\"LayProcessBar\" style='DISPLAY:none; Z-INDEX:1; LEFT:150px;WIDTH:500px; POSITION:absolute; TOP:250px; HEIGHT:5px; BACKGROUND-COLOR:#eaeaea; layer-background-color:#EAEAEA'>-</div>");
            switch (tag)
            {
                case "1":
                    OnProcess(page);
                    break;
                case "2":
                    DownProcess(page);
                    break;
            }
        }

        public static void DownProcess(Page page)
        {
            page.Response.Clear();
            page.Response.Buffer = true;
            page.Response.Write("<script language='javascript'>");
            page.Response.Write(" var i;");
            page.Response.Write("LayProcessBar.innerText= '';");

            page.Response.Write("function ClearWait()");
            page.Response.Write("{");
            page.Response.Write("	LayProcessBar.style.display = 'none';");
            page.Response.Write("	window.clearInterval();");
            page.Response.Write("}");
            page.Response.Write(" ClearWait();</script>");
            page.Response.Flush();

        }

        public static void OnProcess(Page page)
        {
            page.Response.Write("<script language='javascript'>");
            page.Response.Write(" var i;");
            page.Response.Write("LayProcessBar.innerText= '';");
            page.Response.Write("function StartShowWait()");
            page.Response.Write("{");
            page.Response.Write("	i = 0;");
            page.Response.Write("	LayProcessBar.style.display = 'inline';");
            page.Response.Write("	window.setInterval('ShowWait()',200);");
            page.Response.Write("}");
            page.Response.Write("function ShowWait()");
            page.Response.Write("{");
            page.Response.Write("	if (i >= 50)");
            page.Response.Write("	{");
            page.Response.Write("		LayProcessBar.innerText='';");
            page.Response.Write("		i = 1;");
            page.Response.Write("	}");
            page.Response.Write("	oDiv = document.createElement('DIV');");
            page.Response.Write("	oDiv.style.position = 'relative';");
            page.Response.Write("	oDiv.style.marginLeft = '1px';");
            page.Response.Write("	oDiv.style.display = 'inline';");
            page.Response.Write("	oDiv.style.backgroundColor = '#35D538';");
            page.Response.Write("	oDiv.style.height = '100%';");
            page.Response.Write("	oDiv.style.width = '9';");
            page.Response.Write("	oDiv.style.height = '5';");
            page.Response.Write("	LayProcessBar.appendChild(oDiv);");
            page.Response.Write("	i++;");
            page.Response.Write("}");
            page.Response.Write("function ClearWait()");
            page.Response.Write("{");
            page.Response.Write("	LayProcessBar.style.display = 'none';");
            page.Response.Write("	window.clearInterval();");
            page.Response.Write("}");
            page.Response.Write("StartShowWait();</script>");
            page.Response.Buffer = true;
            page.Response.Flush();
        }
    }
}
